home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / GSDMO_11.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-02  |  4KB  |  134 lines

  1. program GSDMO_11;
  2. {------------------------------------------------------------------------------
  3.                          DBase Relational File Maker
  4.  
  5.        Copyright (c)  Richard F. Griffin
  6.  
  7.        20 January 1993
  8.  
  9.        102 Molded Stone Pl
  10.        Warner Robins, GA  31088
  11.  
  12.        -------------------------------------------------------------
  13.        This unit creates the files that will be used to demonstrate
  14.        how to link the relationships between dBase files for data
  15.        retrieval based on common fields in two files.
  16.  
  17.        The code is fairly complex in this routine, since it is busy
  18.        creating random data for transaction records.  It is available
  19.        for review, with no promise of how much this will contribute
  20.        to an understanding of specific Griffin Solutions commands.
  21.  
  22.        This will first build a master file and then create a transaction
  23.        file using the UNIQUEID field in the master file as the key.  The
  24.        transactions will insert the UNIQUEID field in each record as the
  25.        MASTERID field.  This field will be used to link back to the master
  26.        record.
  27.  
  28.        A Master file index on the UNIQUEID field will be created.
  29.        A Master file index on the LASTNAME+FIRSTNAME will be created.
  30.        A Transaction file index on the MASTERID field will be created.
  31.  
  32.        The Master file will have the structure as defined in GSOB_GEN.PAS.
  33.        The Transaction file structure is:
  34.  
  35.              MASTERID     C    8   0      Uses UNIQUEID from Master Record
  36.              FULLNAME     C   40   0      In Lastname~FirstName format
  37.              TRANDATE     D    8   0
  38.              AMOUNT       N    8   2
  39.              PAYTYPE      C    1   0
  40.  
  41.        New procedures/functions introduced are:
  42.  
  43.                  FieldPut
  44.                  NumberPut
  45.  
  46. -------------------------------------------------------------------------------}
  47.  
  48. uses
  49.    GSOB_Str,
  50.    GSOB_DBF,
  51.    GSOB_Gen,
  52.    GSOB_Var,
  53.    GSOBShel,
  54.    {$IFDEF WINDOWS}
  55.       WinCRT,
  56.       WinDOS;
  57.    {$ELSE}
  58.       CRT,
  59.       DOS;
  60.    {$ENDIF}
  61.  
  62.  
  63. var
  64.    t : string;
  65.    ix : integer;
  66.    rn : integer;
  67.    FLoc : integer;
  68.  
  69.    tfRanNum   : word;
  70.    tfUniqId   : string[8];
  71.    tfFullName : string[40];
  72.    tfTranDate : longint;
  73.    tfAmount   : FloatNum;
  74.    tfPayType  : FloatNum;
  75.    tfPayTypeS : string[1];
  76.  
  77.             {Routine to create a transaction file}
  78.  
  79. Procedure MakeTranFile;
  80. var
  81.    f : GSO_DB3Build;
  82. begin
  83.    f.Init('GSDMO_TF');
  84.    f.InsertField('MASTERID','C',8,0);
  85.    f.InsertField('FULLNAME','C',40,0);
  86.    f.InsertField('TRANDATE','D',8,0);
  87.    f.InsertField('AMOUNT','N',8,2);
  88.    f.InsertField('PAYTYPE','C',1,0);
  89.    f.Done;
  90. end;
  91.  
  92. begin
  93.    ClrScr;
  94.    Writeln('Making GSDMO_MF.DBF Master File');
  95.    MakeTestData(3,'GSDMO_MF', 20, false);
  96.    WriteLn('GSDMO_MF Complete');
  97.    Writeln('Making GSDMO_TF.DBF Transaction File');
  98.    MakeTranFile;
  99.    WriteLn('GSDMO_TF Complete');
  100.    WriteLn('Creating Transactions');
  101.    Select(1);
  102.    Use('GSDMO_MF');
  103.    IndexOn('GSDMO_ID','UNIQUEID');
  104.    IndexOn('GSDMO_NM','LASTNAME + FIRSTNAME');
  105.    Select(2);
  106.    Use('GSDMO_TF');
  107.    IndexOn('GSDMO_TN','MASTERID');
  108.    Randomize;
  109.    for rn := 1 to 50 do
  110.    begin
  111.       ix := Random(20) + 1;
  112.       Select(1);
  113.       Go(ix);                           {Read a random master record}
  114.       tfUniqId := FieldGet('UNIQUEID');
  115.       tfFullName := StringGet('LASTNAME') + '~' +
  116.                     StringGet('FIRSTNAME');
  117.       tfTranDate := Date - Random(31);
  118.       tfAmount := (Random(30000) + 100);
  119.       tfAmount := tfAmount/100;
  120.       tfPayType := Random(4);
  121.       str(tfPayType:1:0,tfPayTypeS);
  122.       Select(2);                        {Change to area 2}
  123.       ClearRecord;
  124.       FieldPut('MASTERID',tfUniqId);
  125.       StringPut('FULLNAME',tfFullName);
  126.       DatePut('TRANDATE',tfTranDate);
  127.       NumberPut('AMOUNT',tfAmount);     {Store tfAmount in AMOUNT}
  128.       FieldPut('PAYTYPE',tfPayTypeS);
  129.       Append;
  130.    end;
  131.    WriteLn('Finished');
  132.    CloseDataBases;
  133. end.
  134.